import { makeAutoObservable } from 'mobx'
import { http, setToken, getToken, removeToken } from '../utils'
class LoginStore {
  token = getToken() || ''
  constructor() {
    //响应式
    makeAutoObservable(this)
  }
  getToken = async ({ identity, password, username, verify }) => {
    //调用登录接口
    const res = await http.post('/user_server/api/v1/pub/user/login', {
      identity, password, username, verify
    })
    //存入token
    this.token = res.data.token
    //存入本地locastation
    setToken(this.token)

  }
  loginOut = () => {
    this.token = ''
    removeToken()
  }
}
export default LoginStore